#ifndef PROXYSERVER_SERVER_MODULE_H
#define PROXYSERVER_SERVER_MODULE_H

#include "PluginModule/IProxyServerNetServerModule.h"
#include "PluginModule/IProxyServerToWorldModule.h"
#include "PluginModule/ILogModule.h"
#include "PluginModule/INetModule.h"
#include "PluginModule/IProxyServerToGameModule.h"
#include "PluginModule/INetClientModule.h"
#include "PluginModule/ISecurityModule.h"
#include "Protocol/Protocol.h"

namespace FragrantGrass
{
	class ProxyServerNetServerModule : public IProxyServerNetServerModule
	{
	public:
		ProxyServerNetServerModule(IPluginManager* p)
		{
			m_pPluginManager = p;
		}

		virtual bool Init();
		virtual bool Shut();
		virtual bool Execute();

		virtual bool AfterInit();

		virtual int Transpond(const SOCK nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);


		virtual int EnterGameSuccessEvent(const GUID xClientID, const GUID xPlayerID);

	protected:

		void OnSocketClientEvent(const SOCK nSockIndex, const FG_NET_EVENT eEvent, INet* pNet);

		void OnClientDisconnect(const SOCK nAddress);
		void OnClientConnected(const SOCK nAddress);

		void OnConnectKeyProcess(const SOCK nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
		void OnReqServerListProcess(const SOCK nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
		void OnSelectServerProcess(const SOCK nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
		void OnReqRoleListProcess(const SOCK nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
		void OnReqCreateRoleProcess(const SOCK nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
		void OnReqDelRoleProcess(const SOCK nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
		void OnReqEnterGameServer(const SOCK nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);

		//////////////////////////////////////////////////////////////////////////

		void OnOtherMessage(const SOCK nSockIndex, const int nMsgID, const char* msg, const uint32_t nLen);
	protected:

		std::map<GUID, SOCK> mxClientIdent;
	protected:
		INetClientModule* m_pNetClientModule;
		ILogModule* m_pLogModule;
		INetModule* m_pNetModule;
		ISecurityModule* m_pSecurityModule;
		IProxyServerToWorldModule* m_pProxyToWorldModule;
	};
}

#endif//PROXYSERVER_SERVER_MODULE_H